package com.tiem_files.utils;

import com.tiem_files.common.Constant;

public class PageUtil {
    /**
     * 根据总数获取总分页数
     * @param totalCount 总数
     * @return 分页数
     */
    public static long getTotalPage(long totalCount){
        return totalCount % Constant.PAGE_SIZE == 0 ? totalCount / Constant.PAGE_SIZE : totalCount / Constant.PAGE_SIZE + 1;
    }

    /**
     * 起始页
     * @param currentPage 当前页码
     * @return 起始页码
     */
    public static long getStratPage(long currentPage){
        return currentPage % Constant.PAGE_COUNT == 0 ? currentPage - Constant.PAGE_COUNT + 1 : (currentPage - currentPage % Constant.PAGE_SIZE) + 1;
    }

    /**
     * 末尾页
     * @param currentPage 当前页
     * @return  末尾页
     */
    public static long getEndPage(long currentPage,long totalCount){
        long stratPage = getStratPage(currentPage);
        long totaPage = getStratPage(totalCount);
        long endPage = stratPage + Constant.PAGE_COUNT - 1;
        return endPage > totaPage ? totaPage : endPage;
    }
}
